function ajax(url) {
    return new Promise((resolve, reject) => {
        const xhr = new XMLHttpRequest();
        xhr.open('GET', url);
        xhr.responseType = 'json';
        xhr.onload = function () {
            if (this.status === 200) {
                resolve(this.response);
            } else {
                reject(new Error(this.statusText));
            }
        };
        xhr.send();
    });
}


ajax('../package.json')
    .then(res => {
        const urls = Object.values(res);
        const tasks = urls.map(url => ajax(url));
        return Promise.all(tasks);
    })
    .then(res => {
        console.log('Promise.all ==> res', res);
    })
    .catch(err => {
        console.log('Promise.all ==> err', err);
    });

const req = ajax('./../package.json');
const timeout = new Promise((resolve, reject) => {
    // const times = 1;
    const times = 500;
    setTimeout(() => {
        reject(new Error('timeout'));
    }, times);
});

Promise.race([req, timeout])
    .then(value => {
        console.log('Promise.race ==> ', value);
    })
    .catch(error => {
        console.log('Promise.race ==> ', error);
    });